<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--品牌数据-->
      <el-col :span="4" :xs="24">
        <!-- <el-card> -->
        <div class="head-container"></div>
        <div class="head-container">
          <el-tree
            :data="treeData"
            :expand-on-click-node="false"
            :props="defaultProps"
            ref="tree"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"
          />
        </div>
        <!-- </el-card>s -->
      </el-col>
      <el-col :span="20" :xs="24">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="100px"
        >
          <el-form-item label="菜品关键词" prop="userName">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入菜品关键词"
              clearable
              style="width: 240px"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
        <el-table :data="dishesList" v-loading="loading" style="width: 100%">
          <el-table-column type="index" label="序号" width="80">
          </el-table-column>
          <el-table-column prop="code" label="代码" width="180">
          </el-table-column>
          <el-table-column prop="name" label="名称"> </el-table-column>
          <el-table-column prop="brandName" label="所属小类"> </el-table-column>
          <el-table-column prop="unitName" label="单位"> </el-table-column>
          <el-table-column prop="stdPrice" label="价格"> </el-table-column>
          <el-table-column prop="isEnable" label="启用状态"> </el-table-column>
          <el-table-column prop="atchType" label="难易程度"> </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button
                @click="setItem(scope.row)"
                type="primary"
                size="mini"
                icon="el-icon-edit"
                >设置</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <el-dialog title="菜品设置" :visible.sync="dialogFormVisible">
      <el-form :model="itemObj">
        <el-form-item label="难易程度" label-width="80">
          <el-select v-model="itemObj.atchType" placeholder="请选择难易程度">
            <el-option label="A" value="A"></el-option>
            <el-option label="B" value="B"></el-option>
            <el-option label="C" value="C"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitSetItem">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getArchItemClassList } from "@/api/liangshi/archItemClass";
import { getAtchItemList, updateItem } from "@/api/liangshi/atchItem";
export default {
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 岗位表格数据
      dishesList: [],
      treeData: [],
      defaultProps: {
        children: "children",
        label: "name",
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: "",
        smallClassId: null,
      },
      dialogFormVisible: false,
      itemObj: {},
    };
  },
  created() {
    this.getTreeList();
    this.getList();
  },
  methods: {
    getTreeList() {
      getArchItemClassList().then((res) => {
        this.treeData = res.archItemList;
      });
    },
    handleNodeClick(data) {
      this.queryParams.smallClassId = data.id;
      this.handleQuery();
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    setItem(row) {
      this.dialogFormVisible = true;
      this.itemObj = row;
    },
    submitSetItem() {
      updateItem(this.itemObj).then((res) => {
        this.$modal.msgSuccess("设置成功");
        this.dialogFormVisible = false;
        this.getList();
      });
    },
    getList() {
      this.loading = true;
      getAtchItemList(this.queryParams).then((res) => {
        this.loading = false;
        this.dishesList = res.rows;
        this.total = res.total;
      });
    },
  },
};
</script>

<style></style>